from flask import Blueprint, jsonify, request
from ..Models import mysql

eg = Blueprint("eg", __name__)


@eg.route("/test", methods=["get"])
def test():
    try:
        return jsonify(code=200, result="hello")
    except Exception as e:
        print(e)
        return jsonify(code=500, result=str(e))


# MySQL查询操作示例
@eg.route("/testMysql", methods=["get", "post"])
def testMysql():
    try:
        # date = request.json["date"]  # get post data
        sql = "SELECT * FROM `by`.`test`;"
        result = mysql.select_db_to_DateFrame(sql)
        print(result)
        return jsonify(code=200, result=result)
    except Exception as e:
        print(e)
        return jsonify(code=500, result=str(e))
